# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: AlexWMF <alexxwmf@gmail.com>

_realname=qxmpp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5.5
pkgrel=1
pkgdesc="Cross-platform C++ XMPP client and server library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=("LGPL")
url="https://github.com/qxmpp-project/qxmpp"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         $([[ ${CARCH} != i686 ]] && echo \
           "${MINGW_PACKAGE_PREFIX}-qt6-base" \
           "${MINGW_PACKAGE_PREFIX}-qt6-5compat" \
           "${MINGW_PACKAGE_PREFIX}-qca-qt6" || echo \
           "${MINGW_PACKAGE_PREFIX}-qt5-base"))
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/qxmpp-project/${_realname}/archive/v${pkgver}.tar.gz")
sha256sums=('b25fba89432c4fd72489d1844f683bfbf4e5aa4cfcfda7a982d6019f8e4529f8')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  mkdir ${srcdir}/build-${MSYSTEM} && cd ${srcdir}/build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    -DBUILD_TESTS=OFF \
    -DBUILD_EXAMPLES=OFF \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd ${srcdir}/build-${MSYSTEM}
  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake --install .

  install -d "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSES/* -t ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/
}
